// pages/login/login.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
   id:""
  },

   // 获取输入账号 
   phoneInput: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },

 
 
  // 获取输入密码 
  passwordInput: function (e) {
    this.setData({
      password: e.detail.value
    })
  },


  name: function (e) {
    this.setData({
      name: e.detail.value
    })
  },

  idcard: function (e) {
    this.setData({
      idcard: e.detail.value
    })
  },

  live: function (e) {
    this.setData({
      live: e.detail.value
    })
  },

  
 
  // 注册
  register: function () {
    var that = this;   
    var warn = null; //warn为当手机号为空或格式不正确时提示用户的文字，默认为空
    if (that.data.phone.length == 0) {
      wx.showToast({
        title: '用户名不能为空',
        icon: 'loading',
        duration: 1000
      })
    } else if (that.data.password.length == 0) {
      wx.showToast({
        title: '密码不能为空',
        icon: 'loading',
        duration: 1000
      })
    }else {
      console.log(that.data.head);
      wx.request({
        url: 'http://47.92.245.109:8080/register',
        method: "POST",
        data: {
          openid: that.data.id,
          username: that.data.phone,
          password: that.data.password,
          name: that.data.name,
          idcard: that.data.idcard,
          live: that.data.live,
          head: that.data.head
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          if (res.data.state == 1) {  //判断是否能正常登录
            warn = "卡号密码不匹配";
            wx.showModal({
              title: '提示',
              content: warn
            })
            return;
          } else {
            
            wx.showToast({
 
              title: '注册成功',
               
              icon: 'success',
               
              duration: 2000,
               
              success:function(){
               console.log(that.data.id)
              wx.navigateTo({
               
              url: '../login/login?id='+that.data.id
               
              })
            }
 
          })

          }
        }
 
      })
 
 
 
    }
  },
 
 
  onLoad: function (options) { 
    this.setData({
      id: options.id,
      head:options.head
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }

 
 

})